const { execSQL } = require('../../db/mysql');

//获取轮播图列表方法
function getList() {
    const sql = 'select * from banner';
    return execSQL(sql);
}

//创建新轮播图
const createNewBanner = (bannerData = {}) => {
    const bannerSrc = bannerData.banner_src;
    const bannerDes = bannerData.banner_des;

    const sql = `insert into banner (banner_src, banner_des) values ('${bannerSrc}', '${bannerDes}')`;
    return execSQL(sql).then(insertedResult => {
        return {
            id: insertedResult.insertId
        }
    });
}

//删除轮播图
const deleteBanner = id => {
    const sql = `delete from banner where banner_id=${id}`
    return execSQL(sql).then(deleteResult => {
        if (deleteResult.affectedRows > 0) {
            return true;
        }
        return false;
    })
}

//导出方法
module.exports = { 
    getList,
    createNewBanner,
    deleteBanner
}